define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/goods_spec_item/index' + location.search,
                    add_url: 'goods/goods_spec_item/add',
                    edit_url: 'goods/goods_spec_item/edit',
                    del_url: 'goods/goods_spec_item/del',
                    multi_url: 'goods/goods_spec_item/multi',
                    import_url: 'goods/goods_spec_item/import',
                    table: 'goods_spec_item',
                }
            });

            var table = $("#table");

            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='spec_group_id']", form)
                    .addClass("selectpage")
                    .data("source", "goods/goods_spec_group/index")
                    .data("primaryKey", "spec_group_id")
                    .data("field", "spec_name")
                    .data("orderBy", "spec_group_id desc");
                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'spec_item_id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                commonSearch: true,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'spec_item_id', title: __('Spec_item_id')},
                        {field: 'spec_group_id', title: __('Spec_group_id'), visible: false, operate: 'LIKE %...%'},
                        {field: 'group.spec_name', title: __('Spec_group_id'), operate: false},
                        {field: 'item_name', title: __('Item_name'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
